package ebook.server;

import com.adobe.dp.epub.ncx.TOCEntry;
import com.adobe.dp.epub.opf.NCXResource;
import com.adobe.dp.epub.opf.OPSResource;
import com.adobe.dp.epub.opf.Publication;
import com.adobe.dp.epub.ops.Element;
import com.adobe.dp.epub.ops.OPSDocument;

public class Epub {
	public Publication epub;
	public Epub(String Title, String Chap, String ContentOfChap) {
		try {
			// create new EPUB document
			epub = new Publication();

			// set up title, author and language
			epub.addDCMetadata("title", Title);
			// epub.addDCMetadata("creator", System.getProperty("user.name"));
			epub.addDCMetadata("language", "en");

			// prepare table of contents
			NCXResource toc = epub.getTOC();
			TOCEntry rootTOCEntry = toc.getRootTOCEntry();

			OPSResource main = epub.createOPSResource("OPS/main.html");

			epub.addToSpine(main);

			// get chapter document
			OPSDocument mainDoc = main.getDocument();

			// add chapter to the table of contents
			TOCEntry mainTOCEntry = toc.createTOCEntry(Chap, mainDoc.getRootXRef());
			rootTOCEntry.add(mainTOCEntry);

			// chapter XHTML body element
			Element body = mainDoc.getBody();

			// add a paragraph
			Element paragraph = mainDoc.createElement("p");
			paragraph.add(ContentOfChap);
			body.add(paragraph);
		
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
